package dao;

import java.util.HashMap;

import org.w3c.dom.Document;

import utility.Dom2Str;
import utility.Util_Trading;
import databean.ItemBean;

public class AddItemDAO {
	
	private static String message;
	
	public static String getMessage() {
		return message;
	}
	
	public static String addItem(ItemBean item) {
		HashMap<String,String> data=new HashMap<String,String>();
		data.put("Title", item.getTitle());
		data.put("Description", item.getDescription());
		data.put("StartPrice", item.getStartPrice());
		data.put("ReservePrice", item.getReservePrice());
		data.put("BuyItNowPrice", item.getBuyItNowPrice());
		//data.put("CategoryID", item.getCategoryID());
		data.put("Location", item.getLocation());
		data.put("ConditionID", item.getConditionID());
		data.put("ListingDuration", item.getListingDuration());
		data.put("PictureURL", item.getPictureURL());
		
		Document response = Util_Trading.sendRequest("AddItem.txt", data);

		
		String ack = response.getElementsByTagName("Ack").item(0).getChildNodes().item(0).getNodeValue();
		
		if (ack.equals("Failure")) {
			
			message = response.getElementsByTagName("LongMessage").item(0).getChildNodes().item(0).getNodeValue();
			return null;
			
		} else {
		
			String item_id = response.getElementsByTagName("ItemID").item(0).getChildNodes().item(0).getNodeValue();
			return item_id;
			
		}
		
	}
	
}
 